package com.smile.ye.http;

import com.smile.ye.data.dto.ProductItemCreateDto;
import com.smile.ye.data.dto.ProductItemQueryDto;
import com.smile.ye.data.dto.ProductItemUpdateDto;
import com.smile.ye.response.Result;
import com.smile.ye.service.ProductItemService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Api(tags = "商品管理")
@RestController
@RequestMapping("/products/items")
public class ProductItemController {
    @Autowired
    ProductItemService service;

    @GetMapping
    @ApiOperation("分页查询")
    public Result query(ProductItemQueryDto dto) {
        return service.query(dto);
    }

    @GetMapping("/{id}")
    @ApiOperation("根据ID查询")
    public Result queryById(@PathVariable String id) {
        return service.queryById(id);
    }

    @PostMapping
    @ApiOperation("创建")
    public Result create(@RequestBody ProductItemCreateDto dto) {
        return service.create(dto);
    }

    @PutMapping("/{id}")
    @ApiOperation("修改")
    public Result update(@PathVariable String id,@RequestBody ProductItemUpdateDto dto) {
        return service.update(id,dto);
    }

    @DeleteMapping("/{id}")
    @ApiOperation("删除")
    public Result remove(@PathVariable String id) {
        return service.remove(id);
    }


}
